/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

import Constant.Constant;

/**
 *
 * @author Phuc
 */
public class connectDB
{
	private static String username = Constant.db_username;
	private static String password = Constant.db_password;
    private static String connectDB = Constant.db_connect;
    
    public static ResultSet ExecuteQuery(String sql)
     {
        ResultSet result  = null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            String connectionURL = connectDB;
            Connection connection = 	DriverManager.getConnection(connectionURL, username, password);
            Statement statement = connection.createStatement();
            String mysql = sql;

            result = statement.executeQuery(mysql);
        }
         catch (ClassNotFoundException ex)
            {
                Logger.getLogger(connectDB.class.getName()).log(Level.SEVERE, null, ex);
            }
        catch (SQLException ex)
        {
            Logger.getLogger(connectDB.class.getName()).log(Level.SEVERE, null, ex);
        }

        return result;

}
     public static int Update(String sql)
     {
         int result = 0;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            String connectionURL = connectDB;
            Connection connection = DriverManager.getConnection(connectionURL, username, password);
            Statement statement = connection.createStatement();
            result = statement.executeUpdate(sql);
        }
         catch (ClassNotFoundException ex)
            {
                Logger.getLogger(connectDB.class.getName()).log(Level.SEVERE, null, ex);
            }
        catch (SQLException ex)
        {
            Logger.getLogger(connectDB.class.getName()).log(Level.SEVERE, null, ex);
        }

        return result;
     }
}
